package com.guoxin.part1.chapter3;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019年8月27日
 */
public class ThreadSleep extends Thread{

	public static void main(String[] args) {
		new Thread(){
			@Override
			public void run() {
				long startTime = System.currentTimeMillis();
				ThreadSleep.sleep(2);
				long endTime = System.currentTimeMillis();
				System.out.println(String.format("Total spend %d ms",(endTime - startTime)));
			}
		}.start();
		long startTime = System.currentTimeMillis();
		sleep(3);
		long endTime = System.currentTimeMillis();
		System.out.println(String.format("Main thread total spend %d ms",(endTime - startTime)));
	}
	
	public static void sleep(int seconds){
		try {
			TimeUnit.SECONDS.sleep(seconds);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
